package com.hzjq.encrypt.encrypt;

import Decoder.BASE64Decoder;
import Decoder.BASE64Encoder;

public class Base64 {

    private BASE64Encoder encoder;
    private BASE64Decoder decoder;

    public static Base64 getInstance() {
        return SingletonHolder.instance;
    }

    private Base64() {
        encoder = new BASE64Encoder();
        decoder = new BASE64Decoder();
    }

    private static class SingletonHolder {
        private static final Base64 instance = new Base64();
    }


    public String encode(byte[] waitforencode) {
        if (waitforencode == null)
            return null;
        return encoder.encode(waitforencode);
    }

    public byte[] decode(String waitfordecode) {
        if (waitfordecode == null)
            return null;
        try {
            return decoder.decodeBuffer(waitfordecode);
        } catch (Exception e) {
            return null;
        }
    }
}
